package com.big.codegen.controller;

import com.big.codegen.domain.dto.CodeGenServiceDTO;
import com.big.codegen.domain.dto.CodegenTableConfigDTO;
import com.big.codegen.service.CodegenService;
import com.big.common.core.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 代码生成控制器
 * </p>
 *
 * @author 山归岿
 * @create 2025-06-25-21:42
 */
@Slf4j
@RestController
@RequestMapping("/codegen")
@RequiredArgsConstructor
@Validated
@Tag(name = "代码生成", description = "代码生成相关接口")
public class CodegenController {

    private final CodegenService codegenService;


    @PostMapping("/generate")
    @Operation(summary = "生成代码")
    public Result<String> generate() {
        // TODO: 实现代码生成逻辑
        return Result.ok("代码生成功能待实现");
    }

    @PostMapping("/download")
    @Operation(summary = "下载代码")
    public ResponseEntity<Resource> downloadCodeZip(@RequestBody CodegenTableConfigDTO dto) {
        return codegenService.downloadCodeZip(dto);
    }

    @PostMapping("/downloadService")
    @Operation(summary = "下载服务代码")
    public ResponseEntity<Resource> downloadService(@RequestBody CodeGenServiceDTO dto, HttpServletResponse response) {
        return codegenService.downloadService(dto, response);
    }
}
